#pragma once

#include <string>

class Task
{
public:
    Task()
    {}
    Task(int x, int y, char op)
        : _x(x)
        , _y(y)
        , _op(op)
        , _exitCode(0)
    {}
    int operator()()
    {
        switch (_op)
        {
        case '+':
            return _x + _y;
        case '-':
            return _x - _y;
        case '*':
            return _x * _y;
        case '/':
        {
            if(0 == _y)
            {
                _exitCode = -1;
                return -1;
            }
            return _x / _y;
        }
        case '%':
        {
            if(0 == _y)
            {
                _exitCode = -1;
                return -1;
            }
            return _x % _y;
        }
        default:
            return 0;
        }
    }
public:
    std::string format()
    {
        return "[退出码: " + std::to_string(_exitCode) + " ]" + "运算: " + std::to_string(_x) + _op + std::to_string(_y);
    }

private:
    int _x;
    int _y;
    char _op;
    int _exitCode;
};
